#include "KeepUp.h"

/* KeepUp Calendar v0.1
 * Team Members:
 * Francois-Xavier Lemire
 * Guan Tengyan
 * Ong Shi Rong
 * Sun Yangge
 * Xie Xin
 */

const string Calendar::MESSAGE_WELCOME = "Welcome to KeepUp!";
const string Calendar::COMMAND_EXIT = "exit";

void Calendar::welcomeMessage() {
	cout<<MESSAGE_WELCOME<<endl;
}

void Calendar::execute() {
	string operation;
	cin>>operation;
	do {
		CommandParser::getDescription(operation);
	} while (operation!=COMMAND_EXIT);
}

void Calendar::command(string operation) {
	COMMAND_TYPE command = convertToEnum(operation);
	switch (command) {
		case TASKADD:
			taskAdd();
			break;
		case TASKDELETE:
			taskDelete();
			break;
		case TASKDISPLAY:
			taskDisplay();
			break;
		case TASKMARKDONE:
			taskMarkDone();
			break;
		case TASKMODIFY:
			taskModify();
			break;
		default:
			break;
	}
}

Calendar::COMMAND_TYPE Calendar::convertToEnum(string operation) {
	return TASKADD;
}

void Calendar::taskAdd() {

}

void Calendar::taskDelete() {

}

void Calendar::taskDisplay() {

}

void Calendar::taskMarkDone() {

}

void Calendar::taskModify() {

}

Task::Task(vector<string> attributes) {
	startYear = stoi(attributes[ATTR::STARTYEAR]);
	startMonth = stoi(attributes[ATTR::STARTMONTH]);
	startDate = stoi(attributes[ATTR::STARTDATE]);
	startHour = stoi(attributes[ATTR::STARTHOUR]);
	startMinute = stoi(attributes[ATTR::STARTMINUTE]);
	endYear = stoi(attributes[ATTR::ENDYEAR]);
	endMonth = stoi(attributes[ATTR::ENDMONTH]);
	endDate = stoi(attributes[ATTR::ENDDATE]);
	endHour = stoi(attributes[ATTR::ENDHOUR]);
	endMinute = stoi(attributes[ATTR::ENDMINUTE]);
	priority = stoi(attributes[ATTR::PRIORITY]);
	taskName = attributes[ATTR::TASKNAME];
	description = attributes[ATTR::DESCRIPTION];
	isDone = getBooleanValue(attributes[ATTR::ISDONE]);
	hasExpired = getBooleanValue(attributes[ATTR::HASEXPIRED]);
}

vector<string> Task::getAttributes() {
	vector<string> attributes;
	attributes[ATTR::STARTYEAR] = startYear;
	attributes[ATTR::STARTMONTH] = startMonth;
	attributes[ATTR::STARTDATE] = startDate;
	attributes[ATTR::STARTHOUR] = startHour;
	attributes[ATTR::STARTMINUTE] = startMinute;
	attributes[ATTR::ENDYEAR] = endYear;
	attributes[ATTR::ENDMONTH] = endMonth;
	attributes[ATTR::ENDDATE] = endDate;
	attributes[ATTR::ENDHOUR] = endHour;
	attributes[ATTR::ENDMINUTE] = endMinute;
	attributes[ATTR::PRIORITY] = priority;
	attributes[ATTR::TASKNAME] = taskName;
	attributes[ATTR::DESCRIPTION] = description;
	attributes[ATTR::ISDONE] = isDone;
	attributes[ATTR::HASEXPIRED] = hasExpired;

	return attributes;
}

bool Task::getBooleanValue(string s) {
	if (s.compare("true") == 0 || s.compare("True") == 0) {
		return true;
	}
	return false;
}


string CommandParser::getCommand(){
	return userInput.front();
}

string CommandParser::getStartYear(string){
	return time.substr(time.find_last_of("/")+1,time.size()-1);
}

string CommandParser::getStartMonth(string){
	return time.substr(time.find_first_of("/")+1,time.find_last_of("/"));

}
string CommandParser::getStartDate(string){
	while (userInput.front()!="on") {
		userInput.erase(userInput.begin());
	}
	userInput.erase(userInput.begin());
	time = userInput.front();
	return time.substr(time.find_first_of("/"));	
}

string CommandParser::getStartHour(){
	while (userInput.front()!="at") {
		userInput.erase(userInput.begin());
	}
	userInput.erase(userInput.begin());
	
	return userInput.front();

}
/*
string CommandParser::getStartMinute(){

}

string CommandParser::getEndYear(){

}

string CommandParser::getEndMonth(){

}

string CommandParser::getEndDate(){

}

string CommandParser::getEndHour(){

}
string CommandParser::getEndMinute(){

}

string CommandParser::getTaskName(){

}
*/
vector<string> CommandParser::getDescription(string s){
	setUserInput(s);
	userInput.erase(userInput.begin());
	vector<string> description;
	while(userInput.front()!= "at"){
		description.push_back(userInput.front());
	}
	return description;
}

void CommandParser::setUserInput(string s) {
	userInput.push_back(s);
}


int main() {

	Calendar calendar1;

	calendar1.welcomeMessage();

	calendar1.execute();

	return 0;
}
